package com;


import java.io.IOException;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

public class JiaMi {
    public static String encryptionTest(byte[] msg) {
        return new BASE64Encoder().encodeBuffer(msg);
    }

    //使用BASE64Decoder对象的decodeBuffer()进行解密
    public static byte[] decodeTest(String str) throws IOException {
        return new BASE64Decoder().decodeBuffer(str);
    }

    //main方法中分别调用加密和解密方法对需要加密、解密的数据进行加密、解密
    public static void main(String[] args) throws IOException {
        String msg = "2020061920183000";
//        System.out.println("没有加密之前:" + msg);

        String msgOfby = encryptionTest(msg.getBytes());
        byte[] bd = msgOfby.getBytes();
//        System.out.println("加密之后的字符串:" + msgOfby);
//        System.out.println(("解密:") + new String(decodeTest(msgOfby)));

        byte[] data = new byte[bd.length + 2];
        data[0] = (byte) 2;
        data[1] = (byte) bd.length;
        for (int i = 0; i < bd.length; i++) {
            data[i + 2] = bd[i];
        }

        byte[] parseData = new byte[data.length - 2];
        for (int j = 2; j < data.length; j++) {
            parseData[j - 2] = data[j];
        }
        String str = new String(parseData);
        System.out.println(str);
        byte[] ss = decodeTest(str);
        System.out.println(new String(ss));
    }


    /**
     * 发送需要加密的内容
     *
     * @param content
     */
    public static void sendCrptyContent(String content) {

    }


}
